package com.ly.common;

import lombok.Data;
/**
* 全局返回类
* 作者:临渊
* 当前时间 2025/8/12 10:09
* {
*   "code": "500",
*   "msg": "参数错误",
*   "data": null
* }
*/
@Data
public class Result<T> {
    //状态码
    private  String code;
    //提示消息
    private  String msg;
    //接口返回内容
    private T data;

    /**
    *  接口返回成功就可以直接返回data,同时状态码和消息都是定义好的
    */
    public Result(T data,StatusEnum statusEnum){
        this.code = statusEnum.getCode();
        this.msg = statusEnum.getMsg();
        this.data = data;
    }
    public Result(StatusEnum statusEnum){
        this.code = statusEnum.getCode();
        this.msg = statusEnum.getMsg();
    }
    public Result(T data){
        this.code = StatusEnum.SUCCESS.getCode();
        this.msg = StatusEnum.SUCCESS.getMsg();
        this.data = data;
    }
    /**
    *  接口异常，错误消息可以自定义
    */
    public Result(StatusEnum statusEnum,String msg){
        this.code = statusEnum.getCode();
        this.msg = msg;
    }
    /**
    * 异常类调用
    */
    public Result(String code,String msg){
        this.code = code;
        this.msg = msg;
    }
}
